from django.contrib import admin

from oa.admin import SimpleModelAdmin, AutoUpdateUserModelAdmin
from .models import *


@admin.register(DocCompanyName)
class DocCompanyNameAdmin(SimpleModelAdmin):
    list_display = ['pk', 'name', 'code']
    list_display_links = ['pk', 'name']


@admin.register(DocDepartmentName)
class DocDepartmentNameAdmin(SimpleModelAdmin):
    list_display = ['pk', 'name', 'code']
    list_display_links = ['pk', 'name']


@admin.register(DocumentLevel)
class DocumentLevelAdmin(SimpleModelAdmin):
    list_display = ['pk', 'level_code']
    list_display_links = ['pk', 'level_code']


@admin.register(DocType)
class DocTypeAdmin(SimpleModelAdmin):
    list_display = ['pk', 'code', 'name']
    list_display_links = ['pk', 'code', 'name']


@admin.register(VersionCode)
class VersionCodeAdmin(SimpleModelAdmin):
    list_display = ['pk', 'code']
    list_display_links = ['pk', 'code']


@admin.register(SopDocument)
class SopDocumentAdmin(AutoUpdateUserModelAdmin):
    readonly_fields = ['link']
    list_display = [
        'pk', 'code', 'name', 'document_type', 'department', 'document_level',
        'current_active', 'version_code', 'file', 'link', 'published_at']
    list_display_links = ['pk', 'code', 'name']
    list_filter = ['document_type', 'document_level', 'department', 'version_code', 'current_active', 'company']
    search_fields = [
        'code', 'name', 'body_purpose', 'body_scope', 'body_definition',
        'body_duties', 'body_program', 'body_related_docs']
    date_hierarchy = 'published_at'
